package br.com.mumakgnod.engine;

public class GameObject {
	private GameGrid gameGrid;
	private int posX, posY, sizeX, sizeY;
	private boolean tangible;
	
	public GameObject(GameGrid grid, int positionX, int positionY, int sizeX, int sizeY) {
		this.gameGrid = grid;
		setPosX(positionX);
		setPosY(positionY);
		setSizeX(sizeX);
		setSizeY(sizeY);
		setTangible(true);
	}
	
	public GameGrid getGameGrid() {
		return gameGrid;
	}
	
	public int getPosX() {
		return posX;
	}
	
	public int getPosY() {
		return posY;
	}
	
	public int getSizeX() {
		return sizeX;
	}
	
	public int getSizeY() {
		return sizeY;
	}
	
	public boolean isTangible() {
		return tangible;
	}
	
	protected void setPosX(int posX) {
		this.posX = (posX >= 0 && posX <= getGameGrid().getSizeX()) ? posX : 0;
	}
	
	protected void setPosY(int posY) {
		this.posY = (posY >= 0 && posY <= getGameGrid().getSizeY()) ? posY : 0;
	}
	
	protected void setSizeX(int sizeX) {
		this.sizeX = (sizeX > 0) ? sizeX : 0;
	}
	
	protected void setSizeY(int sizeY) {
		this.sizeY = (sizeY > 0) ? sizeY : 0;
	}
	
	protected void setTangible(boolean tangible) {
		this.tangible = tangible;
	}
	
	public boolean hasCollide(GameObject gObj) {
		return !((this.getPosX() + this.getSizeX() < gObj.getPosX()) ||
				 (gObj.getPosX() + gObj.getSizeX() < this.getPosX()) ||
				 (this.getPosY() + this.getSizeY() < gObj.getPosY()) ||
				 (gObj.getPosY() + gObj.getSizeY() < this.getPosY()));
		//return !((X1+W1<X2) or (X2+W2<X1) or (Y1+H1<Y2) or (Y2+H2<Y1)));
	}

}